package com.dfe.backend.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 【描述】： 公共控制器
 *
 * @author LiChang
 * @since 2024-2-23 9:56
 */
public class BaseController {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 【描述】:共享方法
     *
     * @author LiChang
     * @since 2024-2-23 9:58
     */
    public void commonMethod() {
        // 具体实现
    }


    /**
     * 【描述】: 特殊手动分页
     *
     * @param items       items
     * @param currentPage currentPage
     * @param pageSize    pageSize
     * @return {@link List<T>}
     * @author LiChang
     * @since 2024-9-11 17:26
     */
    public <T> List<T> getPage(List<T> items, int currentPage, int pageSize) {
        if (items == null || items.isEmpty() || currentPage <= 0 || pageSize <= 0) {
            throw new IllegalArgumentException("Invalid arguments");
        }
        int startIndex = (currentPage - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, items.size());
        return items.subList(startIndex, endIndex);
    }


}
